package org.lzfto.flink.demo;

import java.util.ArrayList;
import java.util.List;

import org.lzfto.flink.demo.business.flinkTest.test.FlinkTestInterface;
import org.lzfto.flink.demo.business.flinkTest.test.SimpleTestService;
import org.lzfto.flink.demo.business.flinkTest.test.enums.FlinkTest;
import org.lzfto.flink.demo.business.flinkTest.test.stream.MqttConnectorTest;
import org.lzfto.flink.demo.common.AppConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson2.JSON;

public class DemoApplication {
	private static Logger LOGGER = LoggerFactory.getLogger(DemoApplication.class);
	/**
	 * 运行作业，必须接收三个参数
	 * @param args  非空，第一个参数是作业名，第二个参数是artemis用户密码，第三个参数是mysql的数据库用户密码
	 */
    public static void main(String[] args) {
		
		if (args==null) {
			LOGGER.error("没有传递参数。必须传递3个参数，第一个是作业名称，第2个参数是artemis密码，第3个参数是mysql密码");
			return;
		}
		else {
			if (args.length!=3) {
				LOGGER.error("参数个数必须是3个。必须传递3个参数，第一个是作业名称，第2个参数是artemis密码，第3个参数是mysql密码");
				return;
			}
		}
    	
    	if (args!=null) {
    		LOGGER.info("接收到参数:{}",JSON.toJSONString(args));
    	}
    	
    	AppConfiguration config=new AppConfiguration();
    	config.setArtemisHost("tcp://39.99.37.29:9803");
    	config.setArtemisUserName("admin");
    	config.setArtemisPassword(args[1]);
    	config.setDbDriverClass("com.mysql.cj.jdbc.Driver");
    	config.setDbUrl("jdbc:mysql://39.99.37.29:9901/test_target?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8");
    	config.setDbUserName("lzf");
    	config.setDbPassword(args[2]);
    	
    	FlinkTestInterface test=new MqttConnectorTest(config);
    	List<FlinkTestInterface> testList=new ArrayList<>();
    	testList.add(test);
    	@SuppressWarnings("resource")
		SimpleTestService testService=new SimpleTestService(testList);
    	testService.runTest(FlinkTest.FLINK_TEST_FROMMQTT_SINKTOJDBC.getNo(),args[0]);
    }
}
